package br.com.LeitorLog.basicas;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

/**
 * ItemTableModel
 *
 * @since 18/02/2013 13:20:29
 */
public class ItemTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	
	private ArrayList<Item> list; 
	private final String[] headers;
	
	public ItemTableModel(ArrayList<Item> list, String[] headers) {
		this.list = list;
		this.headers =headers; 
	}
	
	/**
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	@Override
	public int getColumnCount() {
		return headers.length;
	}

	/**
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	@Override
	public int getRowCount() {
		return list.size();
	}

	/**
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return list.get(rowIndex);
	}
	
	// a method to add a new line to the table
	public void add(Item item) {
		// make it an array[2] as this is the way it is stored in the ArrayList
		// (not best design but we want simplicity)
//		String[] str = new String[5];
//		str[0] = item.getDataInclusao();
//		str[1] = item.getDescricao();
//		str[2] = item.isLegendario() + "";
//		str[3] = item.getTipo();
//		str[4] = item.getScore() + "";
		list.add(item);
		// inform the GUI that I have change
		fireTableDataChanged();
	}

}
